﻿using System;
using System.Collections.Generic;

using Agile.Service.Rbac;

using Microsoft.AspNetCore.Mvc;

namespace Web.Areas.Rbac.Controllers
{
    [Area("rbac")]
    public class UserController : BaseController<User>
    {
        private readonly IUserService _userService;
        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        public List<User> GetUsers(string orgId)
        {
            return _userService.GetUsers(orgId);
        }
        [HttpPost]
        [HttpGet]
        public override IActionResult GetJGridPageDataJson(Paging paging)
        {
            string sqlwhere = " 1=1 ";
            if (!string.IsNullOrWhiteSpace(paging.keyword))
            {
                sqlwhere += $" and (Account like ('%{paging.keyword}%') " +
                    $"OR Name like ('%{paging.keyword}%') " +
                    $"OR Idcard like ('%{paging.keyword}%') " +
                    $"OR Mobile like ('%{paging.keyword}%')) ";

                paging.page = 1;
            }
            paging.sqlwhere = sqlwhere;
            JQridPageData pageData = Repository.GetJGridPageData(paging);
            return Content(pageData.ToJson());
        }
    }
}